<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">
    <link rel="stylesheet" href="__PUBLIC__/static/css/style.css">
    <link rel="icon" href="__PUBLIC__/static/image/code.png">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body class="body">

<form class="layui-form" action="" method="post" id="addform">
  <div class="layui-form-item">
    <label class="layui-form-label">标题</label>
    <div class="layui-input-block">
      <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="标题" class="layui-input">
    </div>
  </div>

	<div class="layui-form-item">
        <label class="layui-form-label">上级分类</label>
        <div class="layui-input-inline">
            <select name="typeid" lay-verify="required" lay-search="">
                {foreach $typename as $key=>$vo}
            	<option value="{$vo.id}">{$vo._name|raw}</option>
                {/foreach}
            </select>
        </div>
	</div>
    <div class="layui-form-item">
        <label class="layui-form-label">关键词</label>
        <div class="layui-input-block">
            <input type="text" name="keywords" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" name="description" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图片上传</label>
        <div class="layui-input-inline">
        	<input type="text" name="type_img" class="layui-input" id="typeimg" value="" readonly="readonly">
		</div>
		<div class="layui-input-block">
			<button type="button" class="layui-btn layui-btn-danger" id="test7"><i class="layui-icon"></i>上传图片</button>
			<div class="layui-inline layui-word-aux">
			  这里以限制 500KB 为例
			</div>
		</div>
    </div>   

	 <div class="layui-form-item layui-form-text">
	    <label class="layui-form-label">内容</label>
	    <div class="layui-input-block">
	      <textarea class="layui-textarea layui-hide" name="body" lay-verify="content" id="LAY_demo_editor"></textarea>
	    </div>
	  </div>

	  <div class="layui-form-item">
	  	<div class="layui-inline">
	    <label class="layui-form-label">状态</label>
	    <div class="layui-input-inline">
	      <input type="radio" name="status" value="1" title="正常" checked="">
	      <input type="radio" name="status" value="0" title="禁止">
	    </div>
	</div>
	<div class="layui-inline">
      <label class="layui-form-label">日期选择</label>
      <div class="layui-input-block">
        <input type="text" name="date" id="date1" autocomplete="off" class="layui-input">
      </div>
    </div>
	</div>


  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">作者</label>
      <div class="layui-input-block">
        <input type="text" name="write" autocomplete="off" class="layui-input" value="{:cookie('write')}">
      </div>
    </div>
  <div class="layui-inline">
      <label class="layui-form-label">点击数</label>
      <div class="layui-input-block">
        <input type="text" name="click" autocomplete="off" class="layui-input">
      </div>
    </div>
  </div>

   
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
 

          
<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<script src="__ADMIN__/js/comm.js" charset="utf-8"></script>
<script>
    layui.use(['jquery', 'form', 'upload', 'laydate', 'layedit', 'laydate','admin'], function() {
      var form = layui.form,
        layer = layui.layer,
        upload = layui.upload,
        $ = layui.$, //重点处
        layedit = layui.layedit,
        laydate = layui.laydate,
        admin = layui.admin;

      //自定义验证规则
      form.verify({
        title: function(value) {
          if (value.length < 2) {
            return '标题至少得2个字符啊';
          }
        }
      });

      laydate.render({
        elem: '#date1'
      });

      layedit.set({
        uploadImage: {
          url: '{:url('admin/Webconfig/upload')}' //接口url
          ,
          type: 'post' //默认post
        }
      });
      //创建一个编辑器
      var editIndex = layedit.build('LAY_demo_editor');
      //设定文件大小限制
      upload.render({
        elem: '#test7',
        url: '{:url('admin/Webconfig/upload')}',
        size: 500 //限制文件大小，单位 KB
          ,
        done: function(res) {
          if (res.code == 0) {
            $('#typeimg').val(res.data.src);
          } else {
            layer.alert(res.msg, {
              title: '上传失败'
            });
          }
          //console.log(res.path)
        }
      });
      //监听指定开关
      // form.on('submit(demo1)', function(data) {
      //   $.post('{:url('add')}', $('#addform').serialize(),
      //     function(data) {
      //       if (data.code == 1) {
      //         layer.alert(data.msg, {
      //           skin: 'layui-layer-molv' //样式类名
      //             ,
      //           closeBtn: 0
      //         }, function() {
      //           location.href = data.url;
      //         });
      //       } else {
      //         layer.msg(data.msg);
      //       }
      //     });
      //   return false;
      // });

    });
</script>

</body>
</html>